/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Images;

import Interface.IClient;

import Interface.IMain;
import StaticClass.ArrSocket;
import java.awt.AlphaComposite;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JPanel;

/**
 *
 * @author Oho
 */
public class RMImages extends Thread {

    Socket sk;
    ObjectInputStream inp;
    IClient pn;
    Rectangle rt;

    public RMImages(Socket sk) {
        this.sk = sk;
//        this.pn = pn;
        pn = new IClient(this);
        pn.setBounds((ArrSocket.ArrClientIMG.size() % 5) * (200 + 20), ((ArrSocket.ArrClientIMG.size()) / 5) * (200 + 20), 200, 200);
        ArrSocket.ArrClientIMG.add(pn);
        ArrSocket.im.SPMachine.add(pn);
    }

    public void ThreadRead() throws IOException {
        try {


            ImageIcon icon = (ImageIcon) inp.readObject();
            Image img = icon.getImage();
            
            img = img.getScaledInstance(pn.getWidth(), pn.getHeight(), Image.SCALE_FAST);
            pn.jLabel1.setIcon(new ImageIcon(img));
    
         //   Graphics graphics = pn.getGraphics();
//            pn.setbo
           // graphics.drawImage(img, 0, 0, pn.getWidth(), pn.getHeight(), pn.jLabel1);
            img.flush();
            //   inp.reset();
            //ArrSocket.im.lpanel.add(pn);
            //IMain.lpanel.add(pn);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RMImages.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    @Override
    public void run() {
        try {
            inp = new ObjectInputStream(sk.getInputStream());
            rt = (Rectangle) inp.readObject();
           
            while (true) {
                try {
                    ThreadRead();
                } catch (IOException ex) {
                    Logger.getLogger(RMImages.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        } catch (IOException ex) {
            Logger.getLogger(RMImages.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(RMImages.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
